<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            width: 320px;
            height: 36px;
            list-style: none;
            border: 1px solid #ccc;
            border-bottom: none;
            padding: 0;
            margin: 0;
        }

        li {
            width: 80px;
            float: left;
            line-height: 36px;
            text-align: center;
            cursor: pointer;
        }

        .container {
            width: 320px;
            height: 400px;
            border: 1px solid #ccc;
            text-align: center;
        }

        .active {
            background-color: red;
        }
    </style>
    <script src="https://unpkg.com/vue@3"></script>
</head>

<body>

    <div id="app">
       <tab-list></tab-list>
    </div>
    <script>
        var { h } = Vue;

        var app = Vue.createApp({});

        app.component('tab-list', {
            data() {
                return { 
                    curNav: 0 // 0: 水果，1：蔬菜, 2: 零食， 3：日用百货
                }
            },
            render: function () {
                const curNav = this.curNav;
                const content = [
                    '我是水果',
                    '我是蔬菜',
                    '我是零食',
                    '我是日用百货'
                ];
        
                var UlNode = h('ul', [
                    h('li', { class: curNav === 0 ? 'active': '', onClick: () => this.handleClick(0) }, '水果'),
                    h('li', { class: curNav === 1 ? 'active': '', onClick: () => this.handleClick(1) }, '蔬菜'),
                    h('li', { class: curNav === 2 ? 'active': '', onClick: () => this.handleClick(2) }, '零食'),
                    h('li', { class: curNav === 3 ? 'active': '', onClick: () => this.handleClick(3) }, '日用百货'),
                ]);
                console.log(curNav)

                var contentNode = h('div', {
                    class: 'container'
                }, [
                    h('p', content[curNav])
                ]);
                return [UlNode, contentNode]
            },
            methods: {
                handleClick(nextNav) {
                    this.curNav = nextNav;
                }
            }
        });

        app.mount('#app');
    </script>
</body>

</html>